<template>
  <div>
    <h1>app</h1>
    <!-- 默认打开页面时加载 -->
    <!-- <h1>{{ result }}</h1> -->
    <!-- <ul>
      <li v-for="item in result" :key="item.stu_id">
        <p>{{ item.stu_id }}</p>
        <p>{{ item.stu_name }}</p>
      </li>
    </ul> -->
    <!-- 点击按钮加载学生信息 -->
    <button @click="showInfo">展示学生信息</button>
    <ul>
      <li v-for="item in result" :key="item.stu_id">
        <p>{{ item.stu_id }}</p>
        <p>{{ item.stu_name }}</p>
      </li>
    </ul>
    <test-post></test-post>
  </div>
</template>

<script>
import TestPost from "./components/TestPost";
export default {
  data() {
    return {
      result: [],
    };
  },
  /* mounted() {
    console.dir(this.$http);
    // this.$http.get() 发送get请求
    // this.$http.post()  发送post请求
    const url = "http://localhost:8000/search_info_not";
    this.$http.get(url).then((data) => {
      console.log(data);
      console.log(data.body);
      this.result = data.body;
    });
  }, */
  /*   async mounted() {
    const url = "http://localhost:8000/search_info_not";
    try {
      let result = await this.$http.get(url);
      this.result = result.body;
    } catch (e) {
      console.log(e);
    }
  }, */
  /* async created() {
    const url = "http://localhost:8000/search_info_not";
    try {
      let result = await this.$http.get(url);
      this.result = result.body;
    } catch (e) {
      console.log(e);
    }
  }, */
  methods: {
    async showInfo() {
      const url = "http://localhost:8000/search_info_not";
      try {
        let result = await this.$http.get(url);
        this.result = result.body;
        console.log(this.result);
      } catch (e) {
        console.log(e);
      }
    },
  },
  components: {
    TestPost,
  },
};
</script>

<style lang="scss" scoped>
</style>